package com.openfarmanager.android.model;

import android.content.res.Resources;
import android.os.Parcel;
import android.os.Parcelable;
import com.openfarmanager.android.App;
import com.openfarmanager.android.R;

import java.io.Serializable;

public enum FileActionEnum implements Parcelable, Serializable {

    COPY, EDIT, DELETE, MOVE, NEW, SELECT, RENAME, FILE_OPEN_WITH, ARCHIVE_EXTRACT, CREATE_BOOKMARK, CREATE_ARCHIVE;
    
    public String getName() {

        Resources res = App.sInstance.getResources();
        switch (this) {
            case COPY:
                return res.getString(R.string.action_copy);
            case EDIT:
                return res.getString(R.string.action_edit);
            case DELETE:
                return res.getString(R.string.action_delete);
            case MOVE:
                return res.getString(R.string.action_move);
            case RENAME:
                return res.getString(R.string.action_rename);
            case FILE_OPEN_WITH:
                return res.getString(R.string.action_open_with);
            case ARCHIVE_EXTRACT:
                return res.getString(R.string.action_archive_extract);
            case CREATE_ARCHIVE:
                return res.getString(R.string.action_create_archive);

        }

        return "";
    }

    public static String[] names(FileActionEnum[] actions) {

        String[] names = new String[actions.length];
        int i = 0;
        for (FileActionEnum action : actions) {
            names[i++] = action.getName();
        }
        
        return names;
    }

    public static final Parcelable.Creator<FileActionEnum> CREATOR = new Parcelable.Creator<FileActionEnum>() {
        public FileActionEnum createFromParcel(Parcel source) {
            return FileActionEnum.values()[source.readInt()];
        }

        public FileActionEnum[] newArray(int size) {
            throw new UnsupportedOperationException();
        }
    };

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeInt(ordinal());
    }
}
